from django.core.files.storage import FileSystemStorage
from django.conf import settings
import os

class CustomStorage(FileSystemStorage):
    # 单例
    _instance = None

    def __new__(cls, *args, **kwargs):
        if not cls._instance:
            cls._instance = super(CustomStorage, cls).__new__(cls, *args, **kwargs)
        return cls._instance

    def __init__(self, location=settings.CUSTOM_STORAGE_LOCATION, base_url=settings.CUSTOM_STORAGE_BASE_URL):
        super().__init__(location, base_url)

    def set_location(self, new_location):
        self.location = new_location
        super().__init__(self.location, self.base_url)